<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/axios.min.js"></script>
    <script src="/js/util.js"></script>
    <script>
        window.onload = function () {
            cutAll(1)
        }

        function cutAll(pageNo) {
            axios.get("/role/cutAll",{
                params:{
                    pageNo
                }
            }).then(e => {
                var info = e.data;
                var str = "";
                for (var i = 0;i < info.records.length;i++){
                    var obj = info.records[i];
                    str += `<tr>
                                <td>${obj.name}</td>
                                <td>
                                    <input type="button" value="删除角色" onclick="delRole(${obj.id})">
                                    <a href="/role/grade.html?id=${obj.id}">查看角色权限</a>
                                    <a href="/role/update.html?id=${obj.id}">修改角色权限</a>
                                </td>
                            </tr>`
                }
                $("bodyData").innerHTML = str;

                var pageStr = "";
                for (var i = 1;i <= info.pages;i++){
                    pageStr += `<a href="javascript:cutAll(${i})">${i}</a>`
                }
                $("cutPageDiv").innerHTML = pageStr;
            });
        }

        function delRole(id) {
            axios.get("/role/del",{
                params: {
                    id
                }
            }).then(e => {
                if (e.data == "ok"){
                    location.href = "/role/role.html";
                }
            })
        }


    </script>
</head>
<body>
    <h2>角色管理</h2>
    <table width="90%" border="1">
        <thead>
            <tr>
                <th>角色名称</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody id="bodyData"></tbody>
    </table>
    <div style="margin: 20px" id="cutPageDiv"></div>
    <div style="width: 300px;margin: 0 auto">
        <a href="add.html">添加用户</a>
    </div>
</body>
</html>